<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="投标部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderDept">
              <j-select-depart @change="handleChange" :disabled="engineerStatus" v-model="model.tenderDept"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投标编制人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderPerson">
              <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderPerson" dictCode="" placeholder="请选择投标编制人" />-->
              <select-user-by-dep :disabled=personStatus  :multi="false"
                                  v-model="model.tenderPerson" ></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投标单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderUnit">
<!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderUnit" dictCode="erp_company_files,file_name,id,del_flag = 0 and audit_status = 2" placeholder="请选择投标单位"/>-->
              <select-Company-input :disabled="finalStatus" v-model="model.tenderUnit"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否需要协调" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="needHelp">
              <j-dict-select-tag
                @input="isTeamworkChange"
                :disabled="finalStatus"
                type="radio"
                v-model="model.needHelp"
                dictCode="YES_OR_NO"
                placeholder="请选择是否需要协调"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="协同人员（多选）"
              v-show="model.needHelp==1"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="helperIds">
              <select-user-by-dep :disabled=finalStatus  :multi="true"
                                  v-model="model.helperIds" ></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
              <a-textarea :maxLength="500" :disabled="formDisabled" v-model="model.remarks" rows="4" placeholder="备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import { putAction } from '../../../../../api/manage'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
export default {
  name: 'ErpOmcTenderUnitForm',
  components: {
    SelectUserByDep,
    SelectCompanyInput
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    changeStatus: {
      type: Boolean,
      default: false,
      required: false
    },
    engineerStatus: {
      type: Boolean,
      default: false,
      required: false
    },
    personStatus: {
      type: Boolean,
      default: false,
      required: false
    },
    finalStatus: {
      type: Boolean,
      default: false,
      required: false
    },
    sp:{// 当前是否是审批页面
        type: Boolean,
        default: false,
        required: false
      }
  },
  data() {
    return {
      editFormDisabled: false,
      engineerFormDisabled: false,
      personFormDisabled: false,
      isShowTeamwork: false,
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        tenderUnit: [
          { required: true, message: '请选择投标单位!' },
        ],
        tenderPerson: [
          { required: true, message: '请选择投标编制人!' },
        ],
        tenderDept: [
          { required: true, message: '请选择投标部门!' },
        ],
      },
      url: {
        add: '/api/erp/omc/tender/erpOmcTenderUnit/add',
        edit: '/api/erp/omc/tender/erpOmcTenderUnit/edit',
        queryById: '/api/erp/omc/tender/erpOmcTenderUnit/queryById'
      },
      unitDictCode: 'erp_company_files,file_name,id,del_flag = 0',
    }
  },
  computed: {
    formDisabled() {
      if (this.sp) {
        return true
      }
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    //是否协同
    isTeamworkChange(e) {
      if (e == '1') {
        this.isShowTeamwork = true
      } else {
        this.model.helperIds = ''
        this.isShowTeamwork = false
      }
    },
    add() {
      this.modelDefault.needHelp = '0'
      this.edit(this.modelDefault);
    },
    edit(record) {
      Object.assign(this.$data, this.$options.data())
      // this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      if(this.model.needHelp==='1'){
        this.isTeamworkChange('1')
      }
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          //debugger;
          if (!this.model.id) {
            this.model.id = parseInt(Math.random() * 1000000000000);
          }
          that.$emit('ok', this.model);
        }

      })
    },
    handleChange(){
      putAction(this.url.edit,this.model).then(res=>{
        console.log(res.result)
      })
    }
  }
}
</script>
